<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\home\models\CategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '分类管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('创建分类', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\ActionColumn'],
            [
                'attribute' => 'id',
                'value' => 'id',
                'headerOptions' => ['width' => '50'],
            ],
            [
                'attribute' => 'cid',
                'value' => 'cid',
                'headerOptions' => ['width' => '100'],
            ],
            'title',
            'code',
            [
                'attribute' => 'sort',
                'value' => 'sort',
                'headerOptions' => ['width' => '80'],
            ],
            //'updated_at',
            //'icon',
            //'count',
            [
                'format' => 'raw',
                'attribute' => 'is_top_show',
                'value' => function($model) {
                    if($model->is_top_show == 1){
                        return '<span class="btn btn-xs btn-success">显示</span>';
                    }else{
                        return '<span class="btn btn-xs btn-danger">不显示</span>';
                    }
                },
                'filter' => ['0' => '不显示', '1' => '显示'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'is_footer_show',
                'value' => function($model) {
                    if($model->is_footer_show == 1){
                        return '<span class="btn btn-xs btn-success">显示</span>';
                    }else{
                        return '<span class="btn btn-xs btn-danger">不显示</span>';
                    }
                },
                'filter' => ['0' => '不显示', '1' => '显示'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'created_at',
                'value' => function($model) {
                    return date('Y-m-d H:i', $model->created_at);
                },
            ],

        ],
    ]); ?>
</div>
